package org.dylan.keepnote;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 
 * 
 * @Copyright: Copyright (c) 2013 FFCS All Rights Reserved
 * @Company: 北京福富软件有限公司
 * @author 陈作朋 Oct 26, 2013
 * @version 1.00.00
 * @history:
 * 
 */
public class KNote {

	private Map<String, String> attrs = new HashMap<String, String>();
	
	private String title;
	
	private String contentType;

	private File path;

	private File content;

	private KNote parent;
	
	private int seq;

	private List<KNote> childs = new ArrayList<KNote>();

	private List<File> imgs=new ArrayList<File>();
	
	public String getName(){
		String title=this.getTitle();
		if(title.length()>90){
			title=title.substring(0, 90);
		}
		return  title + "(" + this.getSeq() + ")";
	}

	public Map<String, String> getAttrs() {
		return this.attrs;
	}

	public void setAttrs(Map<String, String> attrs) {
		this.attrs = attrs;
	}

	public File getPath() {
		return this.path;
	}

	public void setPath(File path) {
		this.path = path;
	}

	public void addAttr(String key, String value) {
		this.attrs.put(key, value);
	}

	public String getAttr(String key) {
		return this.attrs.get(key);
	}

	public KNote getParent() {
		return this.parent;
	}

	public void setParent(KNote parent) {
		this.parent = parent;
	}

	public List<KNote> getChilds() {
		return this.childs;
	}

	public void setChilds(List<KNote> childs) {
		this.childs = childs;
	}

	public void addChild(KNote child) {
		this.childs.add(child);
	}

	public boolean isNoteDir() {
		return "application/x-notebook-dir".equals(this.attrs.get("content_type"));
	}

	public File getContent() {
		return this.content;
	}

	public void setContent(File content) {
		this.content = content;
	}
		
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	
	public int getSeq() {
		return seq;
	}

	public void setSeq(int seq) {
		this.seq = seq;
	}

	public List<File> getImgs() {
		return imgs;
	}

	public void setImgs(List<File> imgs) {
		this.imgs = imgs;
	}

	public void addImg(File img){
		this.imgs.add(img);
	}

	public boolean isText(){
		return "text/xhtml+xml".equals(this.attrs.get("content_type"));
	}
	
	public boolean isPDF(){
		return "application/pdf".equals(this.attrs.get("content_type"))||"application/octet-stream".equals(this.attrs.get("content_type"));
	}
	
	public boolean isShell(){
		return "text/x-sh".equals(this.attrs.get("content_type"));
	}
	
	public boolean isEXE(){
		return "application/x-msdos-program".equals(this.attrs.get("content_type"))||"application/octet-stream".equals(this.attrs.get("content_type"));
	}
	
	public boolean isTar() {
		return "application/x-tar".equals(this.attrs.get("content_type"));
	}
	
	public boolean isZip() {
		return "application/zip".equals(this.attrs.get("content_type"));
	}
	
	public boolean isChm(){
		return "chemical/x-chemdraw".equals(this.attrs.get("content_type"));
	}
	
	public boolean isXml(){
		return "application/xml".equals(this.attrs.get("content_type"));
	}
	
	public boolean isPPT(){
		return "application/vnd.ms-powerpoint".equals(this.attrs.get("content_type")) || "application/vnd.openxmlformats-officedocument.presentationml.presentation".equals(this.attrs.get("content_type"));
	}
	
	public boolean isDOC(){
		return "application/msword".equals(this.attrs.get("content_type")) || "application/vnd.openxmlformats-officedocument.wordprocessingml.document".equals(this.attrs.get("content_type"));
	}
	
	public boolean isJAVA(){
		return "text/x-java".equals(this.attrs.get("content_type"));
	}
	
	public boolean isTXT(){
		return "text/plain".equals(this.attrs.get("content_type"));
	}
	
	public boolean isRAR(){
		return "application/rar".equals(this.attrs.get("content_type"));
	}
	
	public boolean isJAR(){
		return "application/java-archive".equals(this.attrs.get("content_type"));
	}
	
	public boolean isXDIFF(){
		return "text/x-diff".equals(this.attrs.get("content_type"));
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}

}
